﻿using System;
using System.Collections.Generic;
using System.Text;
using NFinal.Action;

namespace NFinal
{
    public class TemplateResult : ActionResult
    {
        public string Url { get; set; }
        public TemplateResult(string contentType="text/html; charset=utf-8")
        {
            this.Url = null;
        }
        public TemplateResult(string url, string contentType = "text/html; charset=utf-8")
        {
            this.Url = url;
        }
        public override void ExecuteResult<TContext, TRequest>(AbstractAction<TContext, TRequest> context)
        {
            if (Url == null)
            {
                context.Render();
            }
            else
            {
                context.Render(this.Url);
            }
            if (this.ContentType?.Length > 0)
            {
                context.contentType = this.ContentType;
            }
            context.Close();
        }
    }
}
